<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	
	
class President Extends MY_Controller
{
	var $current_user;
	
	public function __construct()
	{
		parent::__construct();
		$this->page_auth->secure_page('president');
		$this->load->model(array('M_school_years','M_enrollees','M_levels','M_users','M_news_and_events'));
		$this->load->library(array('form_validation'));
		$this->current_user = $this->session->userdata('username').' - '.$this->session->userdata('userType');
	}
		
	public function index()
	{	
		$this->view_data['system_message'] = $this->_msg();
	}
	
	public function master_list_by_grade_level()
	{
		$this->load->model('M_grade_level_sections');
		
		$sy = $this->M_school_years->get_set_school_year();
			
		foreach($sy as $syd):
			$syfrom = $syd->sy_from;
			$syto = $syd->sy_to;
		endforeach;
		
		$this->view_data['grade_level_data'] = $this->M_levels->get_all_levels();
		
		$this->view_data['grade_level_sections_data'] = $this->M_grade_level_sections->get_all_sections();
		
		$this->view_data['count_enrollees'] = $this->M_grade_level_sections->count_enrollees_per_section($syfrom,$syto);
	}
	
	/*Create News And Events*/
	function createnewsandevents()
	{ 

		if($this->form_validation->run('news_and_events') == FALSE)
		{

		}
		else
		{	
			$input['caption'] = $this->input->post('caption',TRUE);
			$input['announcement_date'] = date('Y-m-d',strtotime($this->input->post('announcement_date',TRUE)));
			$input['announcement'] = $this->input->post('announcement',TRUE);
			$input['posted_by'] = $this->session->userdata('userType');
		
			if($this->M_news_and_events->add_news_and_events($input)['status'] == 'true')
			{
				$this->view_data['system_message'] ='<div class="success">Data was Successfully Added</div>';					
			}
			elseif($this->M_news_and_events->add_news_and_events($input)['status'] == 'exist')
			{
				$this->view_data['system_message'] ='<div class="error">Data already Exists</div>';					
			}
			elseif($this->M_news_and_events->add_news_and_events($input)['status'] == 'false')
			{
				$this->view_data['system_message'] ='<div class="error">Error was encountered while processing request,Please Try Again Later</div>';					
			}
		}
	}
	
	/*Retrieve News And Events*/
	function newsandevents()
	{
		$this->view_data['date'] = $this->M_news_and_events->get_news_and_events();
		$this->view_data['total_rows'] = $this->M_news_and_events->count_news_and_events();
	
		$config['day_type'] = 'long'; 
		$config['show_next_prev'] = TRUE; 
		$config['next_prev_url'] = 'http://K12.gocloudsaas.info/president/newsandevents/'; 
		
		$config['template'] = '
			{table_open}<table class="calendar">{/table_open}
			{heading_row_start}<tr>{/heading_row_start}
			{heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
			{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
			{heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}
			{heading_row_end}</tr>{/heading_row_end}
			{week_day_cell}<th class="day_header">{week_day}</th>{/week_day_cell}
			{cal_cell_content}<a class="with_content" href="{content}">{day}</a>{/cal_cell_content}
			{cal_cell_content_today}<a class="today_with_content" href="{content}">{day}</a>{/cal_cell_content_today}
			{cal_cell_no_content}<span class="day_listing">{day}</span>&nbsp;{/cal_cell_no_content}
			{cal_cell_no_content_today}<div class="today"><span class="day_listing">{day}</span></div>{/cal_cell_no_content_today}
		';  
		
		$this->load->library('calendar',$config);
	}
	
	/*Show News And Events*/
	function shownewsandevents($year,$month,$day)
	{
		$this->view_data['announcements'] = $this->M_news_and_events->get_news_and_events_today($year,$month,$day);
	}

	public function test()
	{
		$this->load->model('m_reports','mr');
		echo '<pre>';
		var_dump($this->mr->total_enrolled_students_with_student_id());
		echo '</pre>';
		die();
	
	}
}